package com.ttai.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.igexin.sdk.PushManager;
import com.ttai.R;
import com.ttai.dagger.componet.activity.DaggerVerifyAcountComponet;
import com.ttai.dagger.module.activity.VerifyAcountPresenterModule;
import com.ttai.model.net.VerifyAccountBean;
import com.ttai.model.net.VerifyIdBean;
import com.ttai.presenter.activity.InsertIdAcountPresenter;
import com.ttai.presenter.activity.InsertNewAcountPresenter;
import com.ttai.presenter.activity.InsertTipAcountPresenter;
import com.ttai.presenter.activity.VerifyAccountPresenter;
import com.ttai.ui.adapter.VerifyIdRecycleViewAdapter;
import com.ttai.ui.adapter.VerifyLoginRecycleViewAdapter;
import com.ttai.ui.base.BaseActivity;
import com.ttai.untils.Constant;
import com.ttai.untils.ItemClickSupport;
import com.ttai.untils.getui.DemoIntentService;

import java.util.ArrayList;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class VerifyLogin extends BaseActivity {


    ArrayList<VerifyAccountBean.SellectListBean> accountArrayList = new ArrayList<>();
    ArrayList<VerifyIdBean.SellectListBean> idArrayList = new ArrayList<>();
    @Bind(R.id.detail_recycler_view)
    RecyclerView detailRecyclerView;
    @Bind(R.id.btn_verify)
    Button btnVerify;
    private String index;
    private VerifyLoginRecycleViewAdapter verifyLoginRecycleViewAdapter;
    private VerifyIdRecycleViewAdapter verifyIdRecycleViewAdapter;

//    private InsertNewAcountPresenter insertNewAcountPresenter;
//    private InsertIdAcountPresenter insertIdAcountPresenter;
//    private InsertTipAcountPresenter insertTipAcountPresenter;

    @Inject
    VerifyAccountPresenter verifyAccountPresenter;


    public String flag;
//    private String loginOrotp;
    private String data;
    private String token;
    private String cid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verifysecurity);
        ButterKnife.bind(this);
        setComponet();


        Intent intent = getIntent();
        index = intent.getStringExtra("index");
        flag = intent.getStringExtra("flag");
//        loginOrotp = intent.getStringExtra("loginOrotp");


        switch (index){
            case "0":{
                accountArrayList = (ArrayList<VerifyAccountBean.SellectListBean>) intent.getSerializableExtra("accoutnList");
                detailRecyclerView.setLayoutManager(new GridLayoutManager(this,3));

                verifyLoginRecycleViewAdapter = new VerifyLoginRecycleViewAdapter(this,accountArrayList);
                detailRecyclerView.setAdapter(verifyLoginRecycleViewAdapter);

                break;
            }
            case "1":{
                idArrayList = (ArrayList<VerifyIdBean.SellectListBean>) intent.getSerializableExtra("idList");
                detailRecyclerView.setLayoutManager(new GridLayoutManager(this,3));

                verifyIdRecycleViewAdapter = new VerifyIdRecycleViewAdapter(this,idArrayList);
                detailRecyclerView.setAdapter(verifyIdRecycleViewAdapter);

                break;
            }
        }
    }

    @Override
    public void next(View view) {

    }

    @Override
    public void pre(View view) {

    }

    @Override
    public void setComponet() {
        DaggerVerifyAcountComponet.builder()
                .verifyAcountPresenterModule(new VerifyAcountPresenterModule(this))
                .build()
                .in(this);
    }


    @OnClick(R.id.btn_verify)
    public void onViewClicked() {
                cid = PushManager.getInstance().getClientid(this);
                token = EnterPage.enterphonenumber;
        switch (index){
            case "0": {
                data = verifyLoginRecycleViewAdapter.getData();
                if (data == ""){
                    Toast.makeText(this,"请至少选择一项",Toast.LENGTH_SHORT).show();
                }else {
                    System.out.println("flag:"+flag+" data:"+data+" token:"+token+" cid:"+cid);
                    verifyAccountPresenter.verifyLogin(flag,data,token,cid);
                }

                break;
            }
            case "1": {
                data = verifyIdRecycleViewAdapter.getData();
                if (data == ""){
                    Toast.makeText(this,"请至少选择一项",Toast.LENGTH_SHORT).show();
                }else {
                    verifyAccountPresenter.verifyLogin(flag,data,token,cid);
                }
            }
        }


    }
}
